//
//  L_SecondRecommendCollectionViewCell.m
//  音悦咖
//
//  Created by dllo on 15/7/14.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "L_SecondRecommendCollectionViewCell.h"

@implementation L_SecondRecommendCollectionViewCell

- (void)dealloc
{
    [_backGroundImage release];
    [_mainImage release];
    [_mainLabel release];
    [_recommendModel release];
    [super dealloc];
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        // 创建底色image
        self.backGroundImage = [[UIImageView alloc] init];
        self.backGroundImage.backgroundColor = [UIColor clearColor];
        [self addSubview:self.backGroundImage];
        [_backGroundImage release];
        
        // 创建ImageView
        self.mainImage = [[UIImageView alloc] init];
        [self.mainImage.layer setCornerRadius:5];
        [self addSubview:self.mainImage];
        [_mainImage release];
        
        // 创建mainLabel
        self.mainLabel = [[UILabel alloc] init];
        self.mainLabel.textAlignment = NSTextAlignmentCenter;
        self.mainLabel.textColor = [UIColor whiteColor];
        self.mainLabel.font = [UIFont systemFontOfSize:15];
        [self.mainLabel setLineBreakMode:NSLineBreakByTruncatingTail];
        [self addSubview:self.mainLabel];
        [_mainLabel release];
        
        
        
    }
    return self;
}

#pragma mark - 布局
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.backGroundImage.frame = self.bounds;
    self.mainImage.frame = CGRectMake(5, 5, layoutAttributes.frame.size.width - 10, (layoutAttributes.frame.size.height - 10) / 5 * 4);
    self.mainLabel.frame = CGRectMake(5, self.mainImage.frame.size.height + 5, layoutAttributes.frame.size.width - 10, (layoutAttributes.frame.size.height - 10) / 5);
    [self.layer setCornerRadius:5];
    self.clipsToBounds = YES;

    
}

#pragma mark - 赋值
- (void)setRecommendModel:(L_PosterModel *)recommendModel
{
    if (_recommendModel != recommendModel) {
        [_recommendModel release];
        _recommendModel = [recommendModel retain];
    }
    // 赋值
    [self.mainImage setImageWithURL:[NSURL URLWithString:recommendModel.pic_url] placeholderImage:[UIImage imageNamed:@"place.jpg"]];
    self.mainLabel.text = recommendModel.name;
    
    
}




@end
